package spil;

import desktop_resources.GUI;

public class Territory extends Ownable{
	private int rent;

	public Territory(int rent, int price, int fieldNumber, String title, String subText, String description) {
		super(fieldNumber, title, subText, description);
		this.rent = rent;
		this.price = price;
		this.fieldNumber = super.fieldNumber;
		this.title = super.title;
		this.subtext = super.subtext;
		this.description = super.description;
	}

	public Territory(int rent) {
		super();
		this.rent = rent;
	}

	public Territory() {
		super();
	}

	public void landOnField(Player p) {
		//		buy = false;
		if(owner == null) {
			boolean buy = GUI.getUserLeftButtonPressed(title + " is not owned", "buy", "ignore");
			if(buy) {
				buy(p);
			}
			else GUI.getUserButtonPressed(p + " did not buy " + title, "ok");
		}
		else {
			if(p!=owner) {
				if(p.account.getBalance() < rent) {
					GUI.getUserButtonPressed(p + " pays " + p.getBalance() + "\nto " + owner, "ok");
					owner.account.insert(p.getBalance());
					p.account.withdraw(p.getBalance());
				}
				else {
					GUI.getUserButtonPressed(p + " pays " + rent + "\nto " + owner, "ok");
					p.account.withdraw(rent);
					owner.account.insert(rent);
				}
			}
			else GUI.getUserButtonPressed(owner + " owns " + title, "ok");
		}
	}

	public void lose() {
		owner = null;
	}

	public int getRent() {
		return rent;
	}

	public String toString() {
		if(owner != null)
			return this.title +  " owned by " + owner + "\n Rent is " + rent;
		return this.title + " isn't owned" ;
	}
}
